import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/login',
      name: '登录',
      component: () => import('../views/Login.vue')
    }, {
      path: '/register',
      name: 'Register',
      component: () => import('../views/Register.vue')
    }, {
      path: "/",
      name: "layout",
      component: () => import('../views/Layout.vue'),
      children: [{
        path: "/home",
        name: "首页",
        component: () => import('../views/home/Home.vue'),
      }, {
        path: "/setting/menu",
        name: "菜单管理",
        component: () => import('../views/setting/MenuList.vue'),
      }, {
        path: "/setting/role",
        name: "角色管理",
        component: () => import('../views/setting/RoleList.vue'),
      }, {
        path: "/setting/user",
        name: "系统管理",
        component: () => import('../views/setting/UserList.vue'),
      }, {
        path: "/setting/myinfo",
        name: "个人信息",
        component: () => import('../views/setting/MyInfo.vue'),
      },
      {
        path: "/system/notice",
        name: "NoticeList",
        component: () => import('../views/system//notice/NoticeList.vue'),
      }, {
        path: "/system/deviceList",
        name: "DeviceList",
        component: () => import('../views/system//device/DeviceList.vue'),
      }, {
        path: "/system/laboratoryList",
        name: "LaboratoryList",
        component: () => import('../views/system/laboratory/LaboraryList.vue'),
      }, {
        path: "/system/applyList",
        name: "ApplyListyList",
        component: () => import('../views/system/apply/ApplyList.vue'),
      }, {
        path: "/myApply",
        name: "MyApplyList",
        component: () => import('../views/myinfo/MyApplyList.vue'),
      }, {
        path: "/myInfo",
        name: "MyInfo",
        component: () => import('../views/myinfo/myInfo.vue'),
      }, {
        path: "/myNotice",
        name: "MyNoticeList",
        component: () => import('../views/myinfo/MyNoticeList.vue'),
      }]
    }
  ]
})

router.beforeEach((to, from, next) => {
  const userInfo = sessionStorage.getItem("userInfo");
  if (!userInfo && to.path != "/login" && to.path != "/register") {
    router.push("/login");
  }
  next();
})

export default router
